package com.only.common.util;

import cn.hutool.core.util.StrUtil;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @author only
 * @date 2023/10/17
 * @description
 */
public class Base64Support {
    /**
     * base64 解码
     * @param content
     * @return
     */
    public static String decode(String content) {
        if (StrUtil.isBlank(content)) return "";
        byte[] base64decodedBytes = Base64.getDecoder().decode(content);
        return new String(base64decodedBytes, StandardCharsets.UTF_8);
    }

    /**
     * base64 编码
     * @param content
     * @return
     */
    public static String encode(String content) {
        if (StrUtil.isBlank(content)) return "";
        return Base64.getEncoder().encodeToString(content.getBytes(StandardCharsets.UTF_8));
    }
}
